package com.zut.blocks.web.controller;

import com.zut.blocks.base.controller.GenericController;
import com.zut.blocks.base.domain.User;
import com.zut.blocks.service.user.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lvxin
 * @Date 2020/12/27 9:25
        */
@RestController
@RequestMapping("/api/user")
public class UserController extends GenericController<User,Integer,UserService> {

    Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    UserService userService;

    /**
     * user regist
     */
    @PostMapping("/regist")
    public User userRegist(@RequestBody User user){
        return userService.saveUser(user);
    }
    /*user delete*/
    @PostMapping("/delete")
    public int userDelete(@RequestParam int id){
        return userService.deleteUser(id);
    }

    /**
     * get all users
     */
    @PostMapping("/getAllUser")
    public List<User> getAllUser(){
        List<User> users = userService.getAllUser();
        users.forEach(System.out::println);
        return userService.getAllUser();
    }



    /**
     * update  user
     */

    @PostMapping("/updateUser")
    public User updateUser(@RequestBody User user){
        return userService.updateUSer(user);
    }

    /**
     *  get user by userNumber
     */
    @PostMapping("/getUserByUserNumber")
    public User getUserByUserNumber(@RequestParam String userNumber){
        return userService.getUserByUserNumber(userNumber);
    }

}
